<?php

namespace LowCode\Core;

use BadMethodCallException;
use Slim\Interfaces\RouteInterface;

/**
 * @method static RouteInterface get(string $pattern, callable|string $callable)
 * @method static RouteInterface post(string $pattern, callable|string $callable)
 * @method static RouteInterface put(string $pattern, callable|string $callable)
 * @method static RouteInterface delete(string $pattern, callable|string $callable)
 * @method static RouteInterface options(string $pattern, callable|string $callable)
 * @method static RouteInterface any(string $pattern, callable|string $callable)
 * @method static RouteInterface map(array $methods,string $pattern, callable|string $callable)
 * @method static RouteInterface group(array $methods,string $pattern, callable|string $callable)
 * @method static RouteInterface redirect(string $from, $to, int $status = 302)
 */
class Router
{
    /**
     * Dynamically handle calls to the class.
     *
     * @param string $method
     * @param array $parameters
     * @return mixed
     *
     * @throws BadMethodCallException
     */
    public static function __callStatic(string $method, array $parameters)
    {
        $app = Admin::factory()->getApp();
        if (!method_exists($app, $method)){
            throw new BadMethodCallException(sprintf(
                'Method %s::%s does not exist.', static::class, $method
            ));
        }
        return $app->{$method}(...$parameters);
    }
}
